<?php

namespace App\Models\Factory;

use App\Models\AbsModelFactory;
use App\Models\Orm\FreeDoubleball;

/**
 * 赠送双色球记录工厂
 * Class FreeDoubleFactory
 * @package App\Models\Factory
 */
class FreeDoubleFactory extends AbsModelFactory
{


    /**
     * 根据用户id获取赠送双色球数据
     *
     * @param  $user_id integer 用户id
     * @return $ball 赠送双色球数据
     */
    public static function getBallByUser($user_id)
    {
        $ball = FreeDoubleball::select('bonuscode', 'phase')
                                ->where(['user_id' => $user_id])
                                ->orderBy('created_at', 'desc')
                                ->get()->toArray();
        return $ball ? : [];
    }

    /**
    * 创建双色球赠送记录
    * @param $data 双色球赠送记录数据 
    *
    */
    public static function createDoubleLog($data)
    {
        return FreeDoubleball::insert($data);
    }


    /**
     * 根据用户id判断该用户是否已赠送12期
     *
     * @param  $user_id integer 用户id
     * @return Boole
     */
    public static function getBallCountByUser($user_id)
    {
        $ball = FreeDoubleball::select('bonuscode')
                                ->where(['user_id' => $user_id])
                                ->get()
                                ->toArray();
        $ballCount = count($ball) ? : 0;
        if($ballCount < 12){
            return true;
        }
        return false;

    }


}
